
capture log close
log using $log/EDS_15_correlation_intensity, text replace

clear
clear matrix
clear mata
set mem 2g
set matsize 800
set more off
set maxvar 20000
set trace off
set varabbrev off


use $data\BA_Statistik_Summary.dta, clear

tostring monat, replace
gen year=substr(monat,1,4)
destring monat year, replace

bys ba year: egen best_avg = mean(best_ges)
bys ba year: keep if _n==1

keep ba year best_avg

keep if year==2007

joinby ba year using $data\mobihilfen_all.dta", unmatched(master)
tab _merge
drop _merge

gen mp=fahrkosten + trennung + umzug + reisekosten
gen alt=uebergang + ausruestung


foreach type in mp alt {
gen log_int_`type'=log(100*`type'/best_avg)
}


sort ba year



foreach var in log_int_mp log_int_alt {
sum `var',d
replace `var'=r(p99) if `var'>=r(p99)
replace `var'=r(p1) if `var'<=r(p1)
}

corr log_int_mp log_int_alt
scalar rho=r(rho)
di rho
local rho2=round(rho,0.001)
di `rho2'
#d;

twoway (scatter log_int_mp log_int_alt, msymbol(o) msize(medlarge)) 
(lfit log_int_mp log_int_alt, lcolor(gs8) lwidth(medthick) lpattern(solid)),
ytitle("Log treatment intensity geographical MP 2007")
xtitle("Log treatment intensity non-geographical MP 2007")
note("Correlation coefficient {&rho} = 0`rho2' ") scheme(s2mono) graphregion(color(white)) legend(off) 
;
#d cr
graph export $data/Figure_A2.png, as(png) replace

	
log close	

